Compute: EC2
EC2 allows you to get a complete computer in the cloud in a matter of seconds. The nice thing about EC2 is that the computer you get will be very similar to the computer you use to develop your software. If you can run your software on your computer, you can almost certainly run it on EC2 without any changes. This is one of EC2’s main advantages compared to other types of compute platforms (such as Lambda): you don’t have to adapt your application to your host.
Instance types#
EC2 is a sophisticated service with dozens of options that you will likely never need. This is the result of the highly varied workloads and use cases serviced by EC2. Nevertheless, the defaults that EC2 comes with are good default choices, and the most consequential decision you will have to make is selecting an instance type. As of the time of writing, EC2 offers 256 different instance types, but they can be narrowed down to a few categories defined by what they’re optimized for:
- CPU
- Memory
- Network
- Storage
- etc.
with different instance sizes for each category.
A snapshot of some of the AWS EC2 latest generation General Purpose (GP) Instance types is shown in the below table.
Instance Size | vCPU | Memory (GiB) | Instance Storage (GiB) | Network Bandwidth (Gbps) | EBS Bandwidth (Mbps) |
m5.large | 2 | 8 | EBS-Only | Up to 10 | Up to 4,750 |
m5.xlarge | 4 | 16 | EBS-Only | Up to 10 | Up to 4,750 |
m5.2xlarge | 8 | 32 | EBS-Only | Up to 10 | Up to 4,750 |
m5.4xlarge | 16 | 64 | EBS-Only | Up to 10 | 4,750 |
m5.8xlarge | 32 | 128 | EBS-Only | 10 | 6,800 |
m5.12xlarge | 48 | 192 | EBS-Only | 10 | 9,500 |
m5.16xlarge | 64 | 256 | EBS-Only | 20 | 13,600 |
m5.24xlarge | 96 | 384 | EBS-Only | 25 | 19,000 |
m5d.large | 2 | 8 | 1 x 75 NVMe SSD | Up to 10 | Up to 4,750 |
m5d.xlarge | 4 | 16 | 1 x 150 NVMe SSD | Up to 10 | Up to 4,750 |
m5d.2xlarge | 8 | 32 | 1 x 300 NVMe SSD | Up to 10 | Up to 4,750 |
m5d.4xlarge | 16 | 64 | 2 x 300 NVMe SSD | Up to 10 | 4,750 |
m5d.8xlarge | 32 | 128 | 2 x 600 NVMe SSD | 10 | 6,800 |
m5d.12xlarge | 48 | 192 | 2 x 900 NVMe SSD | 10 | 9,500 |
m5d.16xlarge | 64 | 256 | 4 x 600 NVMe SSD | 20 | 13,600 |
m5d.24xlarge | 96 | 384 | 4 x 900 NVMe SSD | 25 | 19,000 |
If you were building your own server, there would be an infinite number of ways to configure it, but with EC2 you get to pick an instance type from its catalog. Sometimes this may seem inefficient because the instance type you settle for might come with resources you don’t need. But this commoditization of server types is what makes it possible for EC2 to exist as a service and to have servers available to be provisioned in a matter of seconds.
Pricing model#
One of the most compelling features of EC2 is that you only pay for the number of seconds your instance is running. If you choose to terminate your instance because you don’t need it anymore or because you want to use a different instance type, you immediately stop getting charged for the terminated instance.
Reserved instances#
EC2 also offers you the option to commit to a long period in exchange for a price reduction. The way this has been done for many years was through reserved instances, where you make 1- or 3-year commitments on a specific instance type in exchange for a substantial price reduction.
Saving plans#
However, a recently released option called savings plans offers equivalent cost savings with some additional flexibility in switching instance types during the period under contract.
With the introduction of savings plans, we don’t see any reason to use reserved instances anymore.
The biggest benefit in using EC2 instances is: you pay for the number of seconds an instance is being used and not by the number of seconds an instance is running.
A)
True
B)
False
Spot instances#
Spot instances are another cost-saving option, where instead of saving money by reserving long-term usage, you save money by allowing EC2 to take away your instance whenever it wants. The cost savings with spot can be even more significant than with reserved instances, but of course not every use case can tolerate having compute capacity taken away from it randomly.
In general, you should think of savings plans, reserved instances, and spot instances as just cost optimization features. You can ignore them and all their implications until you need to start improving your EC2 efficiency.
Remember that these are not free discounts. They come at the cost of more complicated capacity management and less optionality.
EC2—network security#
Let’s end with what’s probably one of the most daunting aspects of EC2—network security. It is complicated because there are many options, but once again the defaults are a very reasonable starting point. There are two important concepts that you will likely have to modify:
- The security group
- The VPC ACL.
Security group#
You can think of security groups as individual firewalls for your instances. With security groups, you can control what goes in and out of your instances.
VPC ACL#
You can think of VPC ACL as a network firewall. With the VPC ACL, you can control what goes in and out of your network.
In Part 2: The Bootstrap Guide, we’ll show you how to set up a robust EC2 setup with all the necessary networking resources.
In the next lesson, we will take a look at EC2 Auto Scaling and it’s different features.